package com.dareway.reflex;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Class_newInstance {
    public static void main(String[] args) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        Class<Student> clazz = Student.class;
//        Student student = clazz.newInstance(); //默认无参构造 公有
//        Student student = clazz.getConstructor(String.class).newInstance("what's up");

//        // 私有构造方法
//        Constructor<Student> constructor = clazz.getDeclaredConstructor(String.class);
//        constructor.setAccessible(true);   //修改访问权限
//
//        Student student = constructor.newInstance("what's up");
//        student.test();

//      调用类方法
    }

    static class Student {
//                public Student(String text){}
//        private Student(String text) {
//        }

        public void test() {
            System.out.println("萨日朗");
        }
    }
}
